<template>
  <div class="loginPage">
    <div class="bg" style="position:relative">
      <div
        class="loginButton"
        style="width:100px;cursor:pointer; padding:10px;background:orange;color:#fff"
      >
        登录
        <div class="viewPro" >
          <el-form
            :model="ruleForm"
            status-icon
            :rules="rules"
            ref="ruleForm"
            label-width="100px"
            class="demo-ruleForm"
          >
            <el-form-item label="账号" prop="pass">
              <el-input type="password" style="width:200px" v-model="ruleForm.pass" autocomplete="off"></el-input>
            </el-form-item>
            <el-form-item label="密码" prop="checkPass">
              <el-input type="password" style="width:200px" v-model="ruleForm.checkPass" autocomplete="off"></el-input>
            </el-form-item>
           
            <el-form-item>
              <el-button type="primary" @click="submitForm('ruleForm')">登录</el-button>
              <el-button @click="resetForm('ruleForm')">忘记密码</el-button>
            </el-form-item>
          </el-form>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
  export default {
    data() {
      var checkAge = (rule, value, callback) => {
        if (!value) {
          return callback(new Error('年龄不能为空'));
        }
        setTimeout(() => {
          if (!Number.isInteger(value)) {
            callback(new Error('请输入数字值'));
          } else {
            if (value < 18) {
              callback(new Error('必须年满18岁'));
            } else {
              callback();
            }
          }
        }, 1000);
      };
      var validatePass = (rule, value, callback) => {
        if (value === '') {
          callback(new Error('请输入密码'));
        } else {
          if (this.ruleForm.checkPass !== '') {
            this.$refs.ruleForm.validateField('checkPass');
          }
          callback();
        }
      };
      var validatePass2 = (rule, value, callback) => {
        if (value === '') {
          callback(new Error('请再次输入密码'));
        } else if (value !== this.ruleForm.pass) {
          callback(new Error('两次输入密码不一致!'));
        } else {
          callback();
        }
      };
      return {
        ruleForm: {
          pass: '',
          checkPass: '',
          age: ''
        },
        rules: {
          pass: [
            { validator: validatePass, trigger: 'blur' }
          ],
          checkPass: [
            { validator: validatePass2, trigger: 'blur' }
          ],
          age: [
            { validator: checkAge, trigger: 'blur' }
          ]
        }
      };
    },
    methods: {
      submitForm(formName) {
        this.$refs[formName].validate((valid) => {
          if (valid) {
            alert('submit!');
          } else {
            console.log('error submit!!');
            return false;
          }
        });
      },
      resetForm(formName) {
        this.$refs[formName].resetFields();
      }
    }
  }
</script>

<style lang="scss" scoped>
.bg {
  width: 100%;
  height: calc(100vh - 50px);

  background: url("../../assets/zjj.jpg") no-repeat center;
  background-size: cover;
}

.viewPro {
  width: 500px;
  height: 300px;
  border-radius: 5px;
  padding-top:50px;
  background: #333;
  opacity: 0.9;
  color: white;
  font-size: 14px;
  text-align: center;
  line-height: 30px;
  position: absolute;
  left: 50px;
  top: 50px;
  transform: translate(-550px, 0px);
  transition: transform 0.35s;
}

.loginButton:hover .viewPro {
  transform: translate(0px, 0px);
}
::v-deep .el-form-item__label{
    color: #fff;
}
</style>
